package edu.uncc.spring2013.itcs3146.group2.multics;



public enum OS {
	INSTANCE; // Singleton instance
	public final int MAX_SEGMENT = 262144;
	public final int SEGMENT_WORDS = 65536;
	public final int PAGE_WORDS = 1024;
	public final int WORD_BITS = 36;
	public final int MAX_MEMORY_WORDS = 16777216; // 2^24 addressable words
	public final int MAX_MEMORY_PAGES = 16384;
	public final int DESCRIPTOR_SEGMENT = 0;
	public final int MAX_DISK_PAGES = 16777216;

	public final int SIM_SEGMENTS = 5;
	public final int SIM_MEM_SIZE_PAGES = 5;

	private Page[] mainMemory;
	private Segment descriptor;
	private Segment[] virtualMemory;
	private MemoryMap memoryMap;
	private Swap swapfile;
	private Segment segmentTable;
	

	OS() {
		virtualMemory = new Segment[SIM_SEGMENTS];
		mainMemory = new Page[SIM_MEM_SIZE_PAGES];
		memoryMap = new MemoryMap(SIM_MEM_SIZE_PAGES);
		swapfile = new Swap(); // we pretend the swap file is unlimited
		descriptor = new Segment(SIM_SEGMENTS);
	}

	public synchronized Word read(VirtualAddress address) {
		/* 
		 * 1. the segment number is used to find the segment descriptor 
		 * 
		 */
		
		Word segmentDescriptor = descriptor.getPage(address.getSegment()).getWord(address.getPage());
		
		/* 
		 * 2. a check is made to see if the segment's page table is in memory. If
		 * the page table is in memory, it is located.  If it is not, a segment fault
		 * occurs.  If there is a protection violation, a fault (trap) occurs.
		 */
		
		// PhysicalAddress pageTable = getPage();

		return null;

	}

	public synchronized void write(VirtualAddress address, Word word) {

	}
}
